import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: '首页',
      icon: 'el-icon-s-promotion'
    }
  }]
},


]

/**
 * asyncRoutes
 * 只有拥有权限的用户，才能显示的路由表
 */
export const asyncRoutes = [{
  path: '/customer',
  component: Layout,
  redirect: '/example/table',
  name: 'Customer',
  meta: {
    title: '客户管理',
    icon: 'el-icon-s-platform',
    roles: ['admin', 'editor']
  },
  children: [
    {
      path: 'company',
      name: 'Company',
      component: () => import('@/views/company/index'),
      meta: {
        title: 'AAAA',
        icon: 'el-icon-office-building',
        roles: ['admin']
      }
    },
    {
      path: 'companydetails',
      name: 'Companydetails',
      component: () => import('@/views/company/details'),
      hidden: true,
      meta: {
        title: 'AAAS',
        icon: 'el-icon-office-building',
        roles: ['admin']
      }
    },
    {
      path: 'companychange',
      name: 'Companychange',
      component: () => import('@/views/company/change'),
      meta: {
        title: 'BBBB',
        icon: 'el-icon-office-building',
        roles: ['admin']
      }
    }
    ,
    {
      path: 'custom',
      name: 'Custom',
      component: () => import('@/views/custom/index'),
      meta: {
        title: 'CCCC',
        icon: 'table',
        roles: ['admin']
      }
    },
    {
      path: 'customdetails',
      name: 'Customdetails',
      component: () => import('@/views/custom/customdetails'),
      hidden: true,
      meta: {
        title: 'CCCS',
        icon: 'table',
        roles: ['admin']
      }
    },

    {
      path: 'demand',
      name: 'Demand',
      component: () => import('@/views/custom/demand'),
      meta: {
        title: 'DDDD',
        icon: 'table',
        roles: ['admin']
      }
    },
    {
      path: 'demanddetails',
      name: 'Demanddetails',
      component: () => import('@/views/custom/demanddetails'),
      hidden: true,
      meta: {
        title: 'DDDS',
        icon: 'table',
        roles: ['admin']
      }
    },

    {
      path: 'disclose',
      name: 'Disclose',
      component: () => import('@/views/disclose/index'),
      meta: {
        title: 'EEEE',
        icon: 'tree',
        roles: ['admin']
      }
    },
    {
      path: 'disclosedetails',
      name: 'Disclosedetails',
      hidden: true,
      component: () => import('@/views/disclose/details'),
      hidden: true,
      meta: {
        title: 'EEES',
        icon: 'tree',
        roles: ['admin']
      }
    },
    {
      path: 'renovation',
      name: 'Renovation',
      component: () => import('@/views/renovation/index'),
      meta: {
        title: 'FFFF',
        icon: 'tree',
        roles: ['admin']
      }
    },
    {
      path: 'renovationDetails',
      name: 'RenovationDetails',
      hidden: true,
      component: () => import('@/views/renovation/renovationDetails'),
      meta: {
        title: 'FFFS',
        icon: 'tree',
        roles: ['admin']
      }
    }
  ]
},
{
  path: '/yuanqu',
  component: Layout,
  redirect: '/park/park',
  name: 'Yuanqu',
  meta: {
    title: '数据分析',
    icon: 'el-icon-s-help',
    roles: ['admin']
  },
  children: [{
    path: 'park',
    name: 'Park',
    component: () => import('@/views/park/index'),
    meta: {
      title: '园区列表',
      icon: 'el-icon-school',
      roles: ['admin']
    }
  },
  {
    path: 'building',
    name: 'Building',
    component: () => import('@/views/building/index'),
    meta: {
      title: '楼宇管理',
      icon: 'el-icon-office-building',
      roles: ['admin']
    }
  },
  {
    path: 'room',
    name: 'Room',
    component: () => import('@/views/room/index'),
    meta: {
      title: '房间管理',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  {
    path: 'addRoom',
    name: 'AddRoom',
    component: () => import('@/views/room/addRoom'),
    hidden: true,
    meta: {
      title: '添加房间',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  {
    path: 'roomDetails',
    name: 'RoomDetails',
    component: () => import('@/views/room/RoomDetails'),
    hidden: true,
    meta: {
      title: '房间详情',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  {
    path: 'leaseRoom',
    name: 'LeaseRoom',
    component: () => import('@/views/leaseRoom/index'),
    meta: {
      title: '租赁信息',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  {
    path: 'addLease',
    name: 'AddLease',
    component: () => import('@/views/leaseRoom/addLease'),
    hidden: true,
    meta: {
      title: '租赁信息',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  {
    path: 'leaseDetails',
    name: 'LeaseDetails',
    component: () => import('@/views/leaseRoom/leaseDetails'),
    hidden: true,
    meta: {
      title: '租赁详情',
      icon: 'el-icon-receiving',
      roles: ['admin']
    }
  },
  // {
  //   path: 'rentroom',
  //   name: 'RentRoom',
  //   component: () => import('@/views/RentRoom/index'),
  //   meta: { title: '房间出租', icon: 'el-icon-receiving' }
  // },
  {
    path: 'car',
    name: 'Car',
    component: () => import('@/views/car/index'),
    meta: {
      title: '车辆管理',
      icon: 'el-icon-truck',
      roles: ['admin']
    }
  }
  ]
},
{
  path: '/nested',
  component: Layout,
  redirect: '/nested/menu1',
  name: 'Nested',
  meta: {
    title: 'GGGG',
    icon: 'nested',
    roles: ['test', "enterprise"]
  },
  children: [
    {
      path: 'kh',
      component: () => import('@/views/nested/kh'),
      name: 'Kh',
      meta: {
        title: 'GGSS',
        icon: 'nested',
      }
    },
    {
      path: 'menu2',
      component: () => import('@/views/nested/menu2/index'),
      name: 'Menu2',
      meta: {
        title: '客户信息',
        icon: 'nested',
      }
    }
  ]
},
{
  path: '/system',
  component: Layout,
  meta: {
    title: '系统管理',
    icon: 'el-icon-s-help',
    roles: ['admin']
  },
  children: [{
    path: 'userInfo',
    name: 'UserInfo',
    component: () => import('@/views/system/userInfo'),
    meta: {
      title: '账号信息',
      icon: 'form'
    }
  },
  {
    path: 'equipment',
    name: 'Equipment',
    component: () => import('@/views/system/equipment'),
    meta: {
      title: '数据字典',
      icon: 'form'
    }
  },
  {
    path: 'role',
    component: () => import('@/views/system/role'),
    name: 'RolePermission',
    meta: {
      title: '角色权限', icon: 'form'
    }
  },
  {
    path: 'menu',
    component: () => import('@/views/system/menu'),
    name: 'Menu',
    meta: {
      title: '菜单管理', icon: 'form'
    }
  },
  {
    path: 'asset',
    name: 'Asset',
    component: () => import('@/views/system/asset'),
    meta: {
      title: '资产管理',
      icon: 'form'
    }
  },
  {
    path: 'test',
    name: 'Test',
    component: () => import('@/views/system/test'),
    meta: {
      title: '资产管理',
      icon: 'form'
    }
  }
  ]
},
{
  path: '*',
  redirect: '/404',
  hidden: true
}
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: '权限',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: '权限页面',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: '权限控制'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: '角色权限',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
